from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-03-08 14:02:28.897518
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 08, Mar, 2022
Time: 14:02:37
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.4336
Nobs: 589.000 HQIC: -48.8420
Log likelihood: 7028.94 FPE: 4.73158e-22
AIC: -49.1026 Det(Omega_mle): 4.06633e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.351193 0.067563 5.198 0.000
L1.Burgenland 0.108405 0.041009 2.643 0.008
L1.Kärnten -0.110635 0.021420 -5.165 0.000
L1.Niederösterreich 0.191409 0.085711 2.233 0.026
L1.Oberösterreich 0.122891 0.084607 1.452 0.146
L1.Salzburg 0.257859 0.043468 5.932 0.000
L1.Steiermark 0.036332 0.057386 0.633 0.527
L1.Tirol 0.101989 0.046347 2.201 0.028
L1.Vorarlberg -0.068527 0.040867 -1.677 0.094
L1.Wien 0.016296 0.075245 0.217 0.829
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.051760 0.145375 0.356 0.722
L1.Burgenland -0.037876 0.088240 -0.429 0.668
L1.Kärnten 0.041816 0.046089 0.907 0.364
L1.Niederösterreich -0.204291 0.184424 -1.108 0.268
L1.Oberösterreich 0.458276 0.182049 2.517 0.012
L1.Salzburg 0.282480 0.093531 3.020 0.003
L1.Steiermark 0.113417 0.123478 0.919 0.358
L1.Tirol 0.304571 0.099726 3.054 0.002
L1.Vorarlberg 0.026152 0.087934 0.297 0.766
L1.Wien -0.027181 0.161906 -0.168 0.867
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.200244 0.034464 5.810 0.000
L1.Burgenland 0.088622 0.020919 4.236 0.000
L1.Kärnten -0.007275 0.010926 -0.666 0.505
L1.Niederösterreich 0.239762 0.043721 5.484 0.000
L1.Oberösterreich 0.161216 0.043158 3.735 0.000
L1.Salzburg 0.040172 0.022173 1.812 0.070
L1.Steiermark 0.025821 0.029273 0.882 0.378
L1.Tirol 0.081925 0.023642 3.465 0.001
L1.Vorarlberg 0.053665 0.020846 2.574 0.010
L1.Wien 0.117941 0.038383 3.073 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.119886 0.034461 3.479 0.001
L1.Burgenland 0.042151 0.020917 2.015 0.044
L1.Kärnten -0.013117 0.010925 -1.201 0.230
L1.Niederösterreich 0.170598 0.043717 3.902 0.000
L1.Oberösterreich 0.338130 0.043154 7.835 0.000
L1.Salzburg 0.099967 0.022171 4.509 0.000
L1.Steiermark 0.109768 0.029270 3.750 0.000
L1.Tirol 0.089856 0.023640 3.801 0.000
L1.Vorarlberg 0.060447 0.020845 2.900 0.004
L1.Wien -0.018022 0.038379 -0.470 0.639
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.124554 0.064827 1.921 0.055
L1.Burgenland -0.044425 0.039349 -1.129 0.259
L1.Kärnten -0.045404 0.020552 -2.209 0.027
L1.Niederösterreich 0.135538 0.082239 1.648 0.099
L1.Oberösterreich 0.161699 0.081180 1.992 0.046
L1.Salzburg 0.284813 0.041708 6.829 0.000
L1.Steiermark 0.058344 0.055062 1.060 0.289
L1.Tirol 0.157431 0.044470 3.540 0.000
L1.Vorarlberg 0.097140 0.039212 2.477 0.013
L1.Wien 0.073494 0.072198 1.018 0.309
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.078873 0.050551 1.560 0.119
L1.Burgenland 0.025310 0.030684 0.825 0.409
L1.Kärnten 0.053182 0.016026 3.318 0.001
L1.Niederösterreich 0.188357 0.064130 2.937 0.003
L1.Oberösterreich 0.332465 0.063304 5.252 0.000
L1.Salzburg 0.034751 0.032524 1.068 0.285
L1.Steiermark 0.007355 0.042937 0.171 0.864
L1.Tirol 0.119234 0.034678 3.438 0.001
L1.Vorarlberg 0.065295 0.030577 2.135 0.033
L1.Wien 0.097109 0.056300 1.725 0.085
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.171460 0.061028 2.810 0.005
L1.Burgenland 0.005081 0.037043 0.137 0.891
L1.Kärnten -0.065925 0.019348 -3.407 0.001
L1.Niederösterreich -0.107184 0.077420 -1.384 0.166
L1.Oberösterreich 0.209071 0.076423 2.736 0.006
L1.Salzburg 0.054313 0.039264 1.383 0.167
L1.Steiermark 0.247074 0.051835 4.767 0.000
L1.Tirol 0.499666 0.041864 11.935 0.000
L1.Vorarlberg 0.064021 0.036914 1.734 0.083
L1.Wien -0.074428 0.067967 -1.095 0.273
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161378 0.067682 2.384 0.017
L1.Burgenland -0.002275 0.041081 -0.055 0.956
L1.Kärnten 0.062883 0.021457 2.931 0.003
L1.Niederösterreich 0.165865 0.085861 1.932 0.053
L1.Oberösterreich -0.055312 0.084755 -0.653 0.514
L1.Salzburg 0.208674 0.043545 4.792 0.000
L1.Steiermark 0.138197 0.057487 2.404 0.016
L1.Tirol 0.055731 0.046429 1.200 0.230
L1.Vorarlberg 0.146859 0.040939 3.587 0.000
L1.Wien 0.121184 0.075378 1.608 0.108
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.392190 0.039750 9.867 0.000
L1.Burgenland -0.003998 0.024127 -0.166 0.868
L1.Kärnten -0.021078 0.012602 -1.673 0.094
L1.Niederösterreich 0.200491 0.050427 3.976 0.000
L1.Oberösterreich 0.230238 0.049777 4.625 0.000
L1.Salzburg 0.036942 0.025574 1.445 0.149
L1.Steiermark -0.016828 0.033762 -0.498 0.618
L1.Tirol 0.090350 0.027268 3.313 0.001
L1.Vorarlberg 0.050766 0.024044 2.111 0.035
L1.Wien 0.043722 0.044269 0.988 0.323
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036694 0.102998 0.167948 0.138074 0.095187 0.080807 0.032032 0.209320
Kärnten 0.036694 1.000000 -0.027710 0.131610 0.048306 0.084666 0.443555 -0.067202 0.089425
Niederösterreich 0.102998 -0.027710 1.000000 0.310943 0.118226 0.270050 0.066025 0.151344 0.288429
Oberösterreich 0.167948 0.131610 0.310943 1.000000 0.212071 0.294015 0.166735 0.135541 0.235175
Salzburg 0.138074 0.048306 0.118226 0.212071 1.000000 0.122059 0.090554 0.104459 0.123169
Steiermark 0.095187 0.084666 0.270050 0.294015 0.122059 1.000000 0.133709 0.105912 0.033010
Tirol 0.080807 0.443555 0.066025 0.166735 0.090554 0.133709 1.000000 0.062758 0.151210
Vorarlberg 0.032032 -0.067202 0.151344 0.135541 0.104459 0.105912 0.062758 1.000000 -0.005094
Wien 0.209320 0.089425 0.288429 0.235175 0.123169 0.033010 0.151210 -0.005094 1.000000